package com.ryan.dispatcher;

import com.ryan.ohos.extension.nested.component.AppBarLayout;
import com.ryan.ohos.extension.nested.component.coordinatorlayout.CoordinatorLayout;
import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.render.Canvas;
import ohos.app.Context;

public class TestBehavior extends CoordinatorLayout.Behavior<Component> {
    public TestBehavior(Context context, AttrSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean layoutDependsOn(CoordinatorLayout parent, Component child, Component dependency) {
        return dependency instanceof AppBarLayout;
    }

    @Override
    public boolean onDependentViewChanged(CoordinatorLayout parent, Component child, Component dependency) {
        int totalScrollRange = ((AppBarLayout) dependency).getTotalScrollRange();
        if (totalScrollRange + dependency.getTop() > (float) child.getEstimatedHeight() / 2) {
            child.setTranslationY(totalScrollRange + dependency.getTop() + 243 - (float) child.getEstimatedHeight() / 2);
        } else {
            child.setTranslationY(243);
        }

        return super.onDependentViewChanged(parent, child, dependency);
    }
}
